# Creates a base debian image with serf/dnsmasq/hadoop
FROM yaolunlun/debian:stable

MAINTAINER yaolun <yaolunlun@sina.com>

# dnsmasq configuration
ADD dnsmasq/* /etc/

# configure serf
ENV SERF_CONFIG_DIR /etc/serf
ADD serf/* $SERF_CONFIG_DIR/
ADD handlers $SERF_CONFIG_DIR/handlers
RUN chmod +x  $SERF_CONFIG_DIR/event-router.sh $SERF_CONFIG_DIR/start-serf-agent.sh

# move all configuration files into container
ADD files/* /usr/local/  

# set jave environment variable 
ENV JAVA_HOME /usr/lib/jvm/java-7-openjdk-amd64 
ENV PATH $PATH:$JAVA_HOME/bin

#configure ssh free key access
RUN mkdir /var/run/sshd && \
    ssh-keygen -t rsa -f ~/.ssh/id_rsa -P '' && \
    cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys && \
    mv /usr/local/ssh_config ~/.ssh/config && \
    sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd

RUN apt-get install tar

#install hadoop stable version v2.7.1
ADD hadoop/hadoop-2.7.1.tar.gz /usr/local/
RUN ln -s /usr/local/hadoop-2.7.1 /usr/local/hadoop && \
    mv /usr/local/bashrc ~/.bashrc && \
    mv /usr/local/hadoop-env.sh /usr/local/hadoop/etc/hadoop/hadoop-env.sh 

